package com.futong.ft.common.handler;

import com.alibaba.fastjson.JSONObject;
import com.futong.ft.common.entity.FTResponse;
import com.futong.ft.common.utils.FTUtil;
import org.springframework.http.MediaType;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class FTAuthExceptionEntryPoint implements AuthenticationEntryPoint {

    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response,
                         AuthenticationException authException) throws IOException {
        FTResponse ftResponse = new FTResponse();
        FTUtil.makeResponse(response,MediaType.APPLICATION_JSON_UTF8_VALUE
                ,HttpServletResponse.SC_UNAUTHORIZED,ftResponse.message("token无效"));
    }
}
